<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    @close="closeDialog()"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="主键id" prop="id" v-if="dataForm.id">
        <el-input v-model="dataForm.id" placeholder="主键id，唯一标识" disabled></el-input>
    </el-form-item>
    <el-form-item label="视频ID" prop="jId">
        <el-input v-model="dataForm.jId" placeholder="示例： 7027440123969015046" disabled></el-input>
    </el-form-item>
    <el-form-item label="原标题" prop="jDesc">
        <el-input v-model="dataForm.jDesc" placeholder="示例： HANGE IS BACK AGAIN THIS MORNING!!!! Everyone say good morning to hange #aot" disabled></el-input>
        <!-- <el-label v-model="dataForm.jDesc" placeholder="示例： HANGE IS BACK AGAIN THIS MORNING!!!! Everyone say good morning to hange #aot" >
          {{dataForm.jDesc}}
        </el-label> -->
    </el-form-item>
    <el-form-item label="中文标题" prop="myTitleCn">
        <el-input v-model="dataForm.myTitleCn" placeholder="示例： 原标题的中文翻译，或者自定义标题"></el-input>
    </el-form-item>
    <el-form-item label="中文标签" prop="myTagsCn">
        <el-input v-model="dataForm.myTagsCn" placeholder="示例： 中文标签"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getObj, addObj, putObj} from '@/api/myvideos'

    export default {
    data () {
      return {
        visible: false,
        canSubmit: false,
        dataForm: {
          id: 0,
          jId: '',
          jDesc: '',
          jCreatetime: '',
          videoId: '',
          videoHeight: '',
          videoWidth: '',
          videoDuration: '',
          videoRatio: '',
          videoCover: '',
          videoOrigincover: '',
          videoDynamiccover: '',
          videoPlayaddr: '',
          videoDownloadaddr: '',
          videoReflowcover: '',
          videoBitrate: '',
          videoEncodedtype: '',
          videoFormat: '',
          videoVideoquality: '',
          videoEncodeusertag: '',
          videoCodectype: '',
          videoDefinition: '',
          statsDiggcount: '',
          statsSharecount: '',
          statsCommentcount: '',
          statsPlaycount: '',
          authorId: '',
          authorUniqueid: '',
          authorNickname: '',
          authorAvatarthumb: '',
          authorAvatarmedium: '',
          authorAvatarlarger: '',
          authorSignature: '',
          authorVerified: '',
          authorSecuid: '',
          authorSecret: '',
          authorFtc: '',
          authorRelation: '',
          authorOpenfavorite: '',
          authorCommentsetting: '',
          authorDuetsetting: '',
          authorStitchsetting: '',
          authorPrivateaccount: '',
          authorstatsFollowingcount: '',
          authorstatsFollowercount: '',
          authorstatsHeartcount: '',
          authorstatsVideocount: '',
          authorstatsDiggcount: '',
          authorstatsHeart: '',
          myTitleCn: '',
          myVideoPath: '',
          myVideoCoverPath: '',
          myAuthorAvatarPath: '',
          myFlagShipinhao: '',
          myFlagDouyin: '',
          myFlagKuaishou: '',
          myFlagWeishi: '',
          myFlagHaokan: '',
          myFlagOthers: '',
          myStatus: '',
          createTime: '',
          createBy: '',
          updateTime: '',
          updateBy: ''
        },
        dataRule: {
          jDesc: [
            { required: false, message: '示例： HANGE IS BACK AGAIN THIS MORNING!!!! Everyone say good morning to hange #aot不能为空', trigger: 'blur' }
          ],
          myTitleCn: [
            { required: true, message: '示例： 原标题的中文翻译，或者自定义标题不能为空', trigger: 'blur' }
          ],
          myTagsCn: [
            { required: true, message: '示例： 中文标签', trigger: 'blur' }
          ],
        }
      }
    },
    methods: {
      init (row) {
        // debugger;
        this.visible = true;
        this.canSubmit = true;
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          getObj(row.id).then(response => {
            this.dataForm = response.data.data
            this.dataForm.jId = this.dataForm.jid
            this.dataForm.jDesc = this.dataForm.jdesc
          })
          return

          // this.$refs['dataForm'].resetFields()
          // console.log(this.dataForm, row)
          this.dataForm = row
          // TODO：属性大小写不一致了！！！
          //    应该是jId，但是拿到的是jid
          this.dataForm.jId = row.jid
          this.dataForm.jDesc = row.jdesc
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.canSubmit = false;
            if (this.dataForm.id) {
                putObj(this.dataForm).then(data => {
                    this.$notify.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            }
            // else {
            //     addObj(this.dataForm).then(data => {
            //         this.$notify.success('添加成功')
            //         this.visible = false
            //         this.$emit('refreshDataList')
            //     }).catch(() => {
            //         this.canSubmit = true;
            //     });
            // }
          }
        })
      },
      //重置表单
      closeDialog() {
          this.$refs["dataForm"].resetFields()
      }
    }
  }
</script>
